#把隱藏層的神經元個數從256調整為1000
model = Sequential()
model.add(Dense(units=1000,input_dim=784,kernel_initializer='normal',activation='relu'))
model.add(Dense(units=10,kernel_initializer='normal',activation='softmax'))
#輸出模型摘要
print(model.summary())
#開始訓練
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])
train_history=model.fit(x=x_Train_normalize,y=y_Train_OneHot,validation_split=0.2,epochs=10,batch_size=200,verbose=2)
訓練結果:
#查看準確率
show_train_history(train_history,'accuracy','val_accuracy')
#預測確率
scores = model.evaluate(x_Test_normalize,y_Test_OneHot)
print()
print('accuracy=',scores[1])
輸出:
10000/10000 [==============================] - 1s 69us/step
accuracy= 0.9785000085830688